package com.albb.controller;

import com.albb.pojo.List;
import com.albb.service.ListService;
import com.albb.util.FastFileUtil;
import com.albb.util.FreemarkerUtil;
import com.albb.util.OSSFileUtil;
import com.albb.util.R;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;

/**
 * @Title:
 * @BelongProjecet Day59
 * @BelongPackage com.albb.controller
 * @Description:
 * @Copyright 研发一部
 * @Author: 马召茹
 * @Date: 2024/5/9 8:55
 * @Version V1.0
 */
@RestController
@RequestMapping("list")
public class ListController {

    @Autowired
    ListService listService;

    @Autowired
    FastFileUtil fastFileUtil;

    //图片上传
    @PostMapping("setList")
    public R setList(MultipartFile file) throws IOException {
        OSSFileUtil util = new OSSFileUtil();
        String s = util.uploadFile(file);
        System.out.println("主");
        System.out.println("从");
        return R.ok().map("upload",s);
    }

    //利用FREEMARKER为景区生成html页面（
    @PostMapping("oneLost/{id}")
    public R oneLost(@PathVariable Integer id) throws TemplateException, IOException {
       // new 一个freemark
        FreemarkerUtil util = new FreemarkerUtil();
        //获取id
        List byId = listService.getById(id);
        //getHM值
        HashMap<String, Object> map = new HashMap<>();
        map.put("byid",byId);
        String aa = util.createHtml(map, "aa", "E:\\" + UUID.randomUUID().toString() + ".html");
        String s = fastFileUtil.uploadFile(new File(aa));
        return R.ok().map("S",s);
    }
}
